package com.practice.designMode.responsibilityChain.validation;

import com.practice.designMode.responsibilityChain.exception.ValidatorException;

public class MaxValidatorHandler implements ValidatorHandler {

    private final Integer max;

    public MaxValidatorHandler(Integer max) {
        this.max = max;
    }

    @Override
    public void validate(Object bean,ValidatorContext validatorContext) throws ValidatorException {
        if(bean instanceof Integer integer){
            if(integer > max){
                validatorContext.appendError(integer + " is bigger than " + max +" Integer value is too large");
            }
        }
    }
}
